package handler

import (
	"github.com/gin-gonic/gin"
	"github.com/lab-online/internal/class/constant"
	"github.com/lab-online/internal/class/entity"
	"github.com/lab-online/pkg/auth"
	mw "github.com/lab-online/pkg/middleware"
	"github.com/lab-online/pkg/resp"
)

type RemoveClassReqParam struct {
	ClassID uint `uri:"id" binding:"required" example:"1"` // 班级ID
}

var RemoveClassValidator = mw.NewValidator(func() *mw.ValidatorOptions {
	return &mw.ValidatorOptions{
		Params: &RemoveClassReqParam{},
	}
})

type RemoveClassRespBody struct {
	resp.BaseRespBody
}

// RemoveClass 删除班级
//
//	@Summary				删除班级
//	@Description			教师可以删除自己的班级，管理员可以删除任何班级
//	@Description.markdown	RemoveClass
//	@Tags					class
//	@Accept					json
//	@Produce				json
//	@Security				bearer
//	@Param					Authorization	header		string	true	"`teacher` | `admin`"
//	@Param					class			path		string	true	"班级ID"
//	@Success				201				{object}	RemoveClassRespBody
//	@Failure				400				{object}	resp.FailedRespBodyString
//	@Failure				403				{object}	resp.FailedRespBodyString
//	@Failure				500				{object}	resp.FailedRespBodyString
//	@x-apifox-status		"developing"
//	@Router					/v1/class/:classID	[delete]
func (h *Handler) RemoveClass(c *gin.Context) {
	classID := c.MustGet(mw.KeyParams).(*RemoveClassReqParam).ClassID
	authEntity := c.MustGet(auth.KeyAuth).(auth.AuthEntity)

	classEntity := entity.NewClassEntity(entity.WithID(classID))

	if err := h.domain.RemoveClass(classEntity, authEntity); err != nil {
		resp.ErrorHandler(c, err)
	} else {
		resp.Success[any](c, constant.CodeRemoveClassSuccess)
	}
}
